home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-16 | 6.0 KB | 210 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWColor.h
- // Release Version: $ ODF 3 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWCOLOR_H
- #define FWCOLOR_H
-
- #ifndef SLCOLOR_H
- #include "SLColor.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTDDEF_H
- #include <FWStdDef.h>
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__QUICKDRAW__)
- #include <QuickDraw.h>
- #endif
-
- // ----- Windows Includes -----
-
- #if defined(FW_BUILD_WIN) && !defined(_INC_WINDOWS)
- #include <windows.h>
- #endif
-
- //========================================================================================
- // Forward Class Declarations
- //========================================================================================
-
- class FW_CColor;
- class FW_CWritableStream;
- class FW_CReadableStream;
-
- //========================================================================================
- // Globale operators << and >>
- //========================================================================================
-
- FW_CWritableStream& operator<<(FW_CWritableStream& stream, const FW_CColor& color);
- FW_CReadableStream& operator>>(FW_CReadableStream& stream, FW_CColor& color);
-
- //========================================================================================
- // class FW_CColor
- //========================================================================================
-
- class FW_CColor : public FW_SColor
- {
- //----------------------------------------------------------------------------------------
- // Constructors/Destructors
- //
- public:
- FW_CColor();
- FW_CColor(const FW_CColor& color);
- FW_CColor(FW_RGBComponent r, FW_RGBComponent g, FW_RGBComponent b);
- FW_CColor(FW_CReadableStream& stream);
- FW_CColor(FW_SColor sColor);
-
- // calls Blend, described below
- FW_CColor(const FW_CColor& colorFrom, const FW_CColor& colorTo, unsigned short numer, unsigned short denom);
-
- #ifdef FW_BUILD_MAC
- FW_CColor(const RGBColor* rgbPtr);
- FW_CColor(const RGBColor& rgb);
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_CColor(COLORREF colorref);
- #endif
-
- //----------------------------------------------------------------------------------------
- // Operators
- //
- public:
- #ifdef FW_BUILD_MAC
- FW_Boolean operator==(const RGBColor& rgb) const;
- FW_Boolean operator!=(const RGBColor& rgb) const;
- #endif
-
- // ----- Assignment operator -----
- FW_CColor& operator=(const FW_CColor& color);
- FW_CColor& operator=(FW_SColor sColor);
-
- #ifdef FW_BUILD_MAC
- FW_CColor& operator=(const RGBColor& rgb);
- operator RGBColor() const;
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_CColor& operator=(RGBQUAD quad);
- operator RGBQUAD() const;
-
- FW_CColor& operator=(RGBTRIPLE triple);
- operator RGBTRIPLE() const;
-
- FW_CColor& operator=(COLORREF colorref);
- operator COLORREF() const;
- #endif
-
- // ----- Arithmetic, by another color -----
- FW_CColor operator+(const FW_CColor& color) const;
- FW_CColor operator-(const FW_CColor& color) const;
-
- FW_CColor& operator+=(const FW_CColor& color);
- FW_CColor& operator-=(const FW_CColor& color);
-
- // ----- Arithmetic by a scalar -----
-
- FW_CColor operator+(unsigned short a) const;
- FW_CColor operator-(unsigned short a) const;
- FW_CColor operator*(unsigned short a) const;
- FW_CColor operator/(unsigned short a) const;
-
- FW_CColor& operator+=(unsigned short a);
- FW_CColor& operator-=(unsigned short a);
- FW_CColor& operator*=(unsigned short a);
- FW_CColor& operator/=(unsigned short a);
-
- //----------------------------------------------------------------------------------------
- // New public API
- //
- public:
- // ----- Set/Get RGB Component -----
- void SetRGB(FW_RGBComponent r, FW_RGBComponent g, FW_RGBComponent b);
-
- // value is returned as unsigned short even though only lower 8 bits are significant
- // this is to facilitate arithmetic on the returned components.
- void GetRGB(unsigned short& r, unsigned short& g, unsigned short& b) const;
-
- FW_Boolean IsDarkerThan(const FW_CColor& color) const;
- FW_Boolean IsLighterThan(const FW_CColor& color) const;
-
- // ----- Set color to average of colorA and colorB
- FW_CColor& Average(const FW_CColor& colorA, const FW_CColor& colorB);
-
- // ----- Scale color proportionately from color 1 to color 2
- FW_CColor& Blend(const FW_CColor& colorFrom, const FW_CColor& colorTo, unsigned short numer, unsigned short denom);
-
- unsigned long Brightness() const;
-
- FW_RGBComponent Red() const;
- FW_RGBComponent Green() const;
- FW_RGBComponent Blue() const;
-
- // ----- Persistence -----
- void Read(FW_CReadableStream& stream);
- void Write(FW_CWritableStream& stream) const;
- };
-
- //========================================================================================
- // inlines
- //========================================================================================
-
- inline FW_RGBComponent FW_CColor::Red() const
- {
- return FW_PrivRGB_R(*this);
- }
-
- inline FW_RGBComponent FW_CColor::Green() const
- {
- return FW_PrivRGB_G(*this);
- }
-
- inline FW_RGBComponent FW_CColor::Blue() const
- {
- return FW_PrivRGB_B(*this);
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CColor::operator!=
- //----------------------------------------------------------------------------------------
- inline FW_Boolean FW_CColor::operator!=(const RGBColor& rgb) const
- {
- return !(*this == rgb);
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // FW_CColor::operator=
- //----------------------------------------------------------------------------------------
-
- inline FW_CColor& FW_CColor::operator=(COLORREF color)
- {
- fRGB = color;
- return *this;
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // FW_CColor::operator COLORREF
- //----------------------------------------------------------------------------------------
-
- inline FW_CColor::operator COLORREF() const
- {
- return fRGB;
- }
- #endif
-
- #endif
-